package site.teamo.biu.flink.web.exception;

import java.util.Optional;

/**
 * @author haocongshun
 * @date 2022/1/12 19:45
 */
public class BiuResponseCode {

    public static final BiuResponseCode LOGIN_FAILED = new BiuResponseCode(10000, "用户名或密码错误");
    public static final BiuResponseCode LOGIN_EXPIRED = new BiuResponseCode(10001, "登录已过期");
    public static final BiuResponseCode PARAMETER_ERROR = new BiuResponseCode(20000, "错误的参数");
    public static final BiuResponseCode GENERAL_ERROR = new BiuResponseCode(20001, "一般异常");

    public final int code;
    public final String msg;

    public BiuResponseCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BiuRuntimeException runtimeException(String msg, Throwable e) {
        return new BiuRuntimeException(code, Optional.ofNullable(msg).orElse(this.msg), e);
    }

    public BiuRuntimeException runtimeException(String msg) {
        return new BiuRuntimeException(code, Optional.ofNullable(msg).orElse(this.msg));
    }

    public BiuRuntimeException runtimeException() {
        return new BiuRuntimeException(code, msg);
    }
}
